

function project_dossier(){
    var _this = this;
    var page;
    _this.page_size = 10;
    _this.init = function(page_project){
        page = page_project;
        _this.initTable();

        $('#click_project_type').on("click", "span", function(){
            $('#click_project_type').find("span").removeClass("active");
            $(this).addClass("active");
            var value = $(this).attr("data-value");
            $("#project_form").find("input[name=project_type]").val(value);
            _this.initTable();
        });
        $('#center_click_project_type').on("click", "span", function(){
            $('#center_click_project_type').find("span").removeClass("active");
            $(this).addClass("active");
            var value = $(this).attr("data-value");
            $("#center_project_form").find("input[name=project_type]").val(value);
            _this.initCenterTable();
        });

        $('#click-project-type').on("click", "span", function(){
            $('#click-project-type').find("span").removeClass("active");
            $(this).addClass("active");
            var value = $(this).attr("data-value");
            if("off_project" == value){
                $("#project_div").hide();
                $("#center_project_div").hide();
                $("#off_project_div").show();
                _this.initOffTable();
            }else if("cen_project" == value){
                $("#project_div").hide();
                $("#off_project_div").hide();
                $("#center_project_div").show();
                _this.initCenterTable();
            }else{
                $("#project_div").show();
                $("#off_project_div").hide();
                $("#center_project_div").hide();
                _this.initTable();
            }
        });
    };

    _this.initTable = function(){
        var list_url = appPath + "/admin/dossier/project/list";
        var project_url = appPath + "/admin/dossier/project/user?project_id=";
        page.init("project_form", list_url, "project_table", "project_page", 1, 10);
        page.goPage(1);
        page.list = function(dataList){
            var len = dataList.length;
            var inner = "", item;
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                inner += '<tr>';
                inner += '<td>' + (i+1) + '</td>';
                inner += '<td>';
                inner += '<span class="text-orange">'+ item['project_name'] + '</span>';
                inner += '</td>';
                inner += '<td>'+ Enum.projectType(item['project_type']) + '</td>';
                var projectType = item['project_type'];
                // if(projectType == '3'){
                //     inner += '<td>'+ TimeUtil.longMsTimeToDateTime3(item['project_start_time']) + '<br/>' + TimeUtil.longMsTimeToDateTime3(item['project_end_time']) + '</td>';
                // }else{
                // }
                inner += '<td>'+ TimeUtil.longMsTimeConvertToDateTime(item['project_start_time']) + '<br/>' + TimeUtil.longMsTimeConvertToDateTime(item['project_end_time']) + '</td>';
                inner += '<td>'+ item['person_count'] + '</td>';
                // var projectMode = item['project_Mode'];
                // if(projectMode == "0"){
                //     inner += '<td>私有</td>';
                // }else if(projectMode == "1"){
                //     inner += '<td>公开</td>';
                // }
                inner += '<td>';
                inner += item['create_user'];
                inner += '</td>';
                inner += '<td>';
                inner += TimeUtil.longMsTimeConvertToDateTime(item['create_time']);
                inner += '</td>';
                inner += '<td>'+Enum.projectStatus(item['project_status'])+'</td>'
                inner += '<td>';
                inner += '<a href="' + project_url + item['id'] + '"  class="a a-info" target="_blank">培训详情</a> ';
                inner += '<a href="' +　appPath + '/admin/dossier/project/export?project_id=' + item['id'] + '&project_type=' + item['project_type']+'&projectName='+item['project_name'] + '" class="a a-view">导出</a>';
                inner += '</td>';
                inner += '</tr>';
            }
            return inner;
        }
    };

    _this.initCenterTable = function () {
        var list_url = appPath + "/admin/dossier/projectCenter/list";
        var project_url = appPath + "/admin/dossier/projectCenter/user?project_id=";
        page.init("center_project_form", list_url, "center_project_table", "center_project_page", 1, 10);
        page.goPage(1);
        page.list = function(dataList){
            var len = dataList.length;
            var inner = "", item;
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                inner += '<tr>';
                inner += '<td>' + (i+1) + '</td>';
                inner += '<td>';
                inner += '<span class="text-orange">'+ item['project_name'] + '</span>';
                inner += '</td>';
                inner += '<td>'+ item['project_type_name'] + '</td>';
                var projectType = item['project_type'];
                // if(projectType == '3'){
                //     inner += '<td>'+ TimeUtil.longMsTimeToDateTime3(item['project_start_time']) + '<br/>' + TimeUtil.longMsTimeToDateTime3(item['project_end_time']) + '</td>';
                // }else{
                // }
                inner += '<td>'+ TimeUtil.longMsTimeConvertToDateTime(item['project_start_time']) + '<br/>' + TimeUtil.longMsTimeConvertToDateTime(item['project_end_time']) + '</td>';
                inner += '<td>'+ item['person_count'] + '</td>';
                // var projectMode = item['project_Mode'];
                // if(projectMode == "0"){
                //     inner += '<td>私有</td>';
                // }else if(projectMode == "1"){
                //     inner += '<td>公开</td>';
                // }
                inner += '<td>';
                inner += item['create_user'];
                inner += '</td>';
                inner += '<td>';
                inner += TimeUtil.longMsTimeConvertToDateTime(item['create_time']);
                inner += '</td>';
                inner += '<td>';
                inner += '<a href="' + project_url + item['project_id'] + '"  class="a a-info" target="_blank">培训详情</a> ';
                inner += '<a href="' +　appPath + '/admin/dossier/projectCenter/export?project_id=' + item['project_id'] + '&project_type=' + item['project_type'] +'&projectName='+item['project_name']+ '" class="a a-view">导出</a>';
                inner += '</td>';
                inner += '</tr>';
            }
            return inner;
        }
    };
    _this.initOffTable = function() {
        var list_url = appPath + "/admin/projectOffline/projectList";
        page.init("off_project_form", list_url, "off_project_table", "off_project_page", 1, _this.page_size);
        page.goPage(1);
        page.list = function(dataList){
            _this.obj = dataList;
            if(dataList == null){
                return;
            }
            var len = dataList.length;
            var inner = "", item;
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                // 组装数据
                inner += "<tr>";
                inner += "<td>"+(parseInt(i)+1)+"</td>";
                inner += "<td><span class=\"text-orange tooltip\" data-length='30'>"+item.projectName+"</span></td>";
                inner += "<td>"+(TimeUtil.longMsTimeConvertToDateTime(item['projectStartTime'])+"<br>"+TimeUtil.longMsTimeConvertToDateTime(item['projectEndTime']))+"</td>";
                inner += "<td>"+item.personCount+"</td>";
                inner += "<td>"+Enum.projectOfflineType(item.projectType)+"</td>";
                inner += "<td>"+item.createUser+"</td>";
                inner += "<td>"+TimeUtil.longMsTimeConvertToDateTime(item.createTime)+"</td>";
                inner += '<td>'+Enum.projectStatus(item.projectStatus)+'</td>'
                inner += '<td><a href="javascript:project_dossier.projectInfo(\''+item.id+'\');" class="a a-info">培训详情</a> ';
                inner += '<a href="' +　appPath + '/admin/dossier/projectOffline/export?project_id=' + item['id'] + '&project_type=' + item['projectType'] +'&projectName='+item['projectName']+ '" class="a a-view">导出</a>';
                inner += "</td>";
                inner += "</tr>";
            }
            return inner;
        }

    };
    _this.search = function(){
        var projectType = $('#click-project-type').find("span[class=active]").attr("data-value");
        if("cen_project" == projectType){
            _this.initCenterTable();
        }else if("off_project" == projectType){
            _this.initOffTable();
        }else{
            _this.initTable();
        }
    };

    _this.searchAll = function(){
        var projectType = $('#click-project-type').find("span[class=active]").attr("data-value");
        if("cen_project" == projectType){
            $('#center_click_project_type').find("span").removeClass("active");
            $('#center_click_project_type span:eq(0)').addClass("active");
            $("#center_project_form").find("input[name=project_name]").val("");
            $("#center_project_form").find("input[name=project_start_time]").val("");
            $("#center_project_form").find("input[name=project_end_time]").val("");
            $("#center_project_form").find("input[name=project_type]").val("");
            _this.initCenterTable();
        }else if("off_project" == projectType){
            $("#off_project_form").find("input[name=projectName]").val("");
            $("#off_project_form").find("input[name=projectStartTime]").val("");
            $("#off_project_form").find("input[name=projectEndTime]").val("");
            _this.initOffTable();
        }else{
            $('#click_project_type').find("span").removeClass("active");
            $('#click_project_type span:eq(0)').addClass("active");
            $("#project_form").find("input[name=project_name]").val("");
            $("#project_form").find("input[name=project_start_time]").val("");
            $("#project_form").find("input[name=project_end_time]").val("");
            $("#project_form").find("input[name=project_type]").val("");
            _this.initTable();
        }



    };

    _this.ajax = function(url, param, type) {
        var result;
        $.ajax({
            url : url,
            async : false,
            type : 'post',
            data : param,
            success : function(data) {
                result = data;
            }
        });
        return result;
    };

    // 项目自定义排序
    _this.sort = function (value, obj) {
        var projectType = $('#click-project-type').find("span[class=active]").attr("data-value");
        if("cen_project" == projectType){
            $("#cenSsortBy").val(value);
            var order = obj.className
            if(order == 'sort asc'){
                $("#cenDescAsc").val('DESC')
            }else{
                $("#cenDescAsc").val('ASC')
            }
            _this.initCenterTable();
        }else if("off_project" == projectType){
            _this.initOffTable();
        }else{
            $("#sortBy").val(value);
            var order = obj.className
            if(order == 'sort asc'){
                $("#descAsc").val('DESC')
            }else{
                $("#descAsc").val('ASC')
            }
            _this.initTable();
        }
    }

    // 培训详情
    _this.projectInfo = function (projectId) {
        var url = appPath + "/admin/dossier/projectOffline/user?projectId="+projectId+"&isDossier="+"4";
        window.open(url,"_blank");
    }
}

var project_dossier = new project_dossier();